async function toggleAccordionAndSelect(element){
    var content = element.nextElementSibling;
    content.style.display = content.style.display === 'block' ? 'none' : 'block';
    console.log("这里请调用请求函数获取到selectData")
    const selectClassData=await requestSelectClass()
    displaySelectData(selectClassData.message)
}


async function displaySelectData(selectClassData){
    const table = document.getElementById('selectClassTable');
    const tbody = table.querySelector('tbody');
    tbody.innerHTML = '';
    selectClassData.forEach(function(row){
        // 创建一个表格行
        const tr = document.createElement('tr');

        const td1 = document.createElement('td');
        td1.textContent = row.ClassName; // 将数据内容放入单元格
        tr.appendChild(td1); // 将单元格添加到行中

        const td2 = document.createElement('td');
        td2.textContent = row.Auto ? "常驻班级":"临时班级"; // 将数据内容放入单元格
        tr.appendChild(td2); // 将单元格添加到行中

        const td3 = document.createElement('td');
        td3.textContent = row.DayOfWeek; // 将数据内容放入单元格
        tr.appendChild(td3); // 将单元格添加到行中

        const td4 = document.createElement('td');
        if (row.AlreadyActive){
            td4.textContent = "已经激活"; // 将数据内容放入单元格
            tr.appendChild(td4); // 将单元格添加到行中
        }else{
            const activeBtn=document.createElement('button');
            activeBtn.innerText="激活"
            activeBtn.addEventListener('click', ()=>{
                activeSelectedClass(row.ClassId)
            })
            td4.appendChild(activeBtn);
        }
        tr.appendChild(td4)

        const td5 = document.createElement('td');
        td5.textContent = row.Index; // 将数据内容放入单元格
        tr.appendChild(td5); // 将单元格添加到行中

        const td6 = document.createElement('td');
        td6.textContent = row.Min; // 将数据内容放入单元格
        tr.appendChild(td6); // 将单元格添加到行中

        const teacherBtnCell = document.createElement('td');
        const teacherBtn=document.createElement('button');
        teacherBtn.innerText="查看id为: "+row.TeacherId+"的教师信息"
        teacherBtn.addEventListener('click', ()=>{
            console.log(row.TeacherId)
            location.href=`../../pages/user/user.html?teacher_id=${row.TeacherId}`
        })
        teacherBtnCell.appendChild(teacherBtn);
        tr.appendChild(teacherBtnCell)

        const courseBtnCell = document.createElement('td');
        const courseBtn=document.createElement('button');
        courseBtn.innerText="查看id为: "+row.CourseId+"的课程"
        courseBtn.addEventListener('click', ()=>{
            console.log(row.CourseId)
            location.href=`../../pages/course/course.html?course_id=${row.CourseId}`
        })
        courseBtnCell.appendChild(courseBtn);
        tr.appendChild(courseBtnCell)



        // 将行添加到 tbody 中
        tbody.appendChild(tr);
    });
}
async function requestSelectClass(){
    const url=`${config.server}`+"/api/admin/select/all/class"
    const data={
        "token":token
    }
    const response=await fetch(url,{
        method:"POST",
        headers: { 'Content-Type': 'application/json' },
        body:JSON.stringify(data)
    })
    const getdata=await response.json()
    if(response.ok){
        console.log(getdata)
        return getdata
    }else{
        console.log("获取数据失败",getdata)
    }
}
async function activeSelectedClass(classId){
    const url=`${config.server}`+"/api/admin/active/class"
    const data={
        "token":token,
        "class_id":classId
    }
    const response=await fetch(url,{
        method:"POST",
        headers: { 'Content-Type': 'application/json' },
        body:JSON.stringify(data)
    })
    const getdata=await response.json()
    if(response.ok){
        alert("激活成功")
        location.reload()
        return getdata
    }else{
        console.log("删除失败",getdata)
        return []
    }
}